from time import sleep, time
import requests
import tkinter as tk
from tkinter import *


#简单的爬取股票信息
def gettrading():
    url = "http://push2.eastmoney.com/api/qt/stock/details/get?ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1,f2,f3,f4&fields2=f51,f52,f53,f54,f55&pos=-11&secid=1.688158" #688158是股票代码，懒得设为变量了
    http_data = requests.Session().get(url=url)
    http_data = eval(http_data.text)
    trading = http_data["data"]['details'][-1]
    return trading




#新建一个窗口，循环显示最后一笔交易时间，交易价格，交易数量
if __name__=="__main__":

    top=tk.Tk()
    top.wm_title("ucloud")
    
    var = tk.StringVar(value=str(gettrading()))
    while(True):
        top.update()  #不断更新
        top.after(10) 
        if True:
            var = tk.StringVar(value=gettrading())
            Label(top, text= str(var.get()) , font = ("黑体",10),).place(anchor = 'nw') 
            sleep(3)   #怕坐牢，每次循环睡眠3秒，没有捕获异常
        
    top.mainloop() 
